<template>
  <div class="hot-list">
    <div class="scroll-container" @touchstart.stop @touchmove.stop>
      <div class="list-container">
        <div class="value-box" v-for="item in listData" :key="item.id">
          <img class="value-img" :src="item.logo" alt="logo"/>
          <p class="value-name">{{ item.name }}</p>
          <p class="value-code font-22">{{ item.code }}</p>
          <p class="value-price font-26">₩ {{ formatPrice(item.price) }}</p>
          <p class="value-change font-22" :class="{'up': item.change >= 0, 'down': item.change < 0}">
            {{ item.change }}%
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'HotList',
  props: {
    listData: {
      type: Array,
      default: () => []
    }
  },
  methods: {
    formatPrice(price) {
      return price.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
    }
  }
}
</script>

<style lang="scss" scoped>
.hot-list {
  padding: 1rem 0 ;

  .scroll-container {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    position: relative;
    z-index: 1;
    
    &::-webkit-scrollbar {
      display: none;
    }
  }

  .list-container {
    display: flex;
    gap: 1rem;
    padding: 0.5rem 0;
    width: fit-content;
    touch-action: pan-x;
  }

  .value-box {
    flex: 0 0 auto;
    width: 27%;
    height: 17rem;
    border: 0.125rem solid #1C1C1E;
    border-radius: 0.875rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2.125rem 1.375rem 0;
    background-color: #0B0B0C;
    user-select: none;

    .value-img {
      width: 3.375rem;
      height: 3.375rem;
      margin-bottom: 1.5rem;
    }

    .value-name {
      color: #FFFFFF;
    //   font-size: 1rem;
      font-weight: 500;
     
    }

    .value-code {
      color: #999999;
    //   font-size: 0.875rem;
      margin-bottom: 0.5rem;
    }

    .value-price {
      color: #FFFFFF;
      font-weight: bold;
      margin-bottom: 0.75rem;
    }

    .value-change {
    //   font-size: 1rem;
      font-weight: 500;

      &.up {
        color: #2abc5a;
        ;
      }

      &.down {
        color: #c7697f;
      }
    }
  }
}
</style>